package com.cdp.web.controller.system;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cdp.common.core.domain.AjaxResult;
import com.cdp.common.core.domain.entity.*;
import com.cdp.common.utils.SecurityUtils;
import com.cdp.common.utils.StringUtils;
import com.cdp.common.utils.poi.ExcelUtil;
import com.cdp.system.dto.*;
import com.cdp.system.service.*;
import com.cdp.system.vo.*;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.lang.reflect.Field;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.net.URLEncoder;
import java.time.LocalDateTime;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
import com.cdp.common.core.controller.BaseController;
import com.cdp.common.core.domain.AjaxResult;
import com.cdp.common.core.domain.entity.SysEfficiencyAgent;
import com.cdp.common.core.domain.entity.SysMechanicalPerformance;
import com.cdp.common.core.domain.entity.SysWaterReducer;
import com.cdp.common.core.page.TableDataInfo;
import com.cdp.framework.config.PageResponse;
import com.cdp.framework.web.service.SysPermissionService;
import com.cdp.system.dto.*;
import com.cdp.system.service.ISysMechanicalPerformanceService;
import com.cdp.system.service.ISysSlumpService;
import com.cdp.system.service.impl.SysPostServiceImpl;
import com.cdp.system.vo.MechanicalPerformanceQueryVO;
import com.cdp.system.vo.MechanicalPerformanceQueryVOSecond;
import com.cdp.system.vo.SysSlumpVO;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.cdp.common.core.controller.BaseController;
import com.cdp.common.core.domain.AjaxResult;
import com.cdp.common.core.domain.entity.SysEfficiencyAgent;
import com.cdp.common.core.domain.entity.SysMechanicalPerformance;
import com.cdp.common.core.domain.entity.SysWaterReducer;
import com.cdp.common.core.page.TableDataInfo;
import com.cdp.common.utils.poi.ExcelUtil;
import com.cdp.framework.config.PageResponse;
import com.cdp.framework.web.service.SysPermissionService;
import com.cdp.system.dto.*;
import com.cdp.system.service.ISysMechanicalPerformanceService;
import com.cdp.system.service.ISysSlumpService;
import com.cdp.system.service.impl.SysPostServiceImpl;
import com.cdp.system.vo.MechanicalPerformanceQueryVO;
import com.cdp.system.vo.MechanicalPerformanceQueryVOSecond;
import com.cdp.system.vo.SysMechanicalPerformanceFourthVO;
import com.cdp.system.vo.SysSlumpVO;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static com.cdp.common.utils.PageUtils.startPage;

/**
 * 力学性能信息
 */
@RestController
@RequestMapping("/system/mechanical")
public class SysMechanicalPerformanceController extends BaseController {
    @Autowired
    private IsysRegionService isysRegionService;

    @Autowired
    private IRegionService regionService;

    @Autowired
    private ISysFlyashService sysFlyashService;

    @Autowired
    private ISysSandFinenesService sysSandFinenesService;

    @Autowired
    private ISysSandTypeService sysSandTypeService;

    @Autowired
    private ISysSandService sysSandService;

    @Autowired
    private ISysStoneGrainService sysStoneGrainService;

    @Autowired
    private ISysFlyashTypeService sysFlyashTypeService;

    @Autowired
    private ISysFlyashFinenessService sysFlyashFinenessService;

    @Autowired
    private ISysWaterReducerTypeService sysWaterReducerTypeService;

    @Autowired
    private ISysCementService sysCementService;

    @Autowired
    private ISysStoneService sysStoneService;

    @Autowired
    private ISysWaterReducerService sysWaterReducerService;

    @Autowired
    private ISysStoneSizeService stoneSizeService;

    @Autowired
    private ISysSourceNameService sysSourceNameService;
    @Autowired
    private ISysEfficiencyMerchantNameService sysEfficiencyMerchantNameService;


    @Autowired
    private ISysMechanicalPerformanceService sysMechanicalPerformanceService;

    @Autowired
    private ISysSlumpService sysSlumpService;

    @Autowired
    private ISysDeformationPerformanceService sysDeformationPerformanceService;

    @Autowired
    private ISysEfficiencyAgentService sysEfficiencyAgent;

    @Autowired
    private ISysDurabilityPerformanceService sysDurabilityPerformanceService;

    @Autowired
    private ISysWaterService waterService;

    @Autowired
    private ISysMineralPowderService sysMineralPowderService;

    @Autowired
    private SysOtherAdmixturesService sysOtherAdmixturesService;


    @Autowired
    private ISysWaterModelService sysWaterModelService;

    @Autowired
    private ISysSwellingagentService sysSwellingagentService;

    @Autowired
    private ISysCementModelService sysCementModelService;


    @Autowired
    private ISysCementStabilityService sysCementStabilityService;

    @Autowired
    private ISysStoneModelService sysStoneModelService;

    @Autowired
    private ISysStoneSpecificationService sysStoneSpecificationService;


    @Autowired
    private ISysStoneParticlesizedistributionService sysStoneParticlesizedistributionService;


    @Autowired
    private ISysMineralModelService sysMineralModelService;

    @Autowired
    private ISysOtherAdmixturesModelService sysOtherAdmixturesModelService;


    @Autowired
    private SysExcelAuditService sysExcelAuditService;

    @Value("${file.excel-mechanical-performance}")
    private String mechanicalPerformanceExcelPath;

    @Autowired
    private IExcelFileHistoryService excelFileHistoryService;

    @Autowired
    private ISysMechanicalPerformanceService mechanicalPerformanceService;


    @GetMapping("listSysMechanicalPerformance")
    public AjaxResult listSysMechanicalPerformance() {

        List<SysMechanicalPerformance> mechanicalPerformanceList = mechanicalPerformanceService.listSysMechanicalPerformance();
        return AjaxResult.success(mechanicalPerformanceList);
    }

    /**
     * 查询力学性能数据
     *
     * @param mechanicalPerformanceQueryDTO 查询条件 DTO
     * @return AjaxResult 包含查询结果列表
     */
     //  @PostMapping("queryMistedMechanicalPerformance")
    public AjaxResult queryMistedMechanicalPerformance(@RequestBody MechanicalPerformanceQueryDTO mechanicalPerformanceQueryDTO) {
        // 调用服务层获取查询结果
        List<MechanicalPerformanceQueryVO> result = mechanicalPerformanceService.queryMistedMechanicalPerformance(mechanicalPerformanceQueryDTO);
        // 返回结果
        return AjaxResult.success(result);
    }


    /**
     * 查询力学性能表
     * @param
     * @return
     */
    /**
     * 查询力学性能表（分页）
     */
    @PostMapping("queryMistedMechanicalPerformance")
    public PageResponse<MechanicalPerformanceQueryVOSecond> queryMistedMechanicalPerformanceSecond(@RequestBody MechanicalPerformanceQueryDTOSecond dto) {
        int pageNum = dto.getPageNum() == null ? 1 : dto.getPageNum();
        int pageSize = dto.getPageSize() == null ? 10 : dto.getPageSize();

        PageHelper.startPage(pageNum, pageSize);
        List<MechanicalPerformanceQueryVOSecond> list = mechanicalPerformanceService.queryMistedMechanicalPerformanceSecond(dto);
        PageInfo<MechanicalPerformanceQueryVOSecond> pageInfo = new PageInfo<>(list);

        return new PageResponse<>(200, "操作成功", pageInfo.getTotal(), pageNum, pageSize, list);
    }






    /**
     * 查询力学性能表
     * @param
     * @return
     */
    /**
     * 查询力学性能表（分页）
     */
    @PostMapping("queryMistedMechanicalPerformanceExportExcel")
    public void queryMistedMechanicalPerformanceExportExcel(HttpServletResponse response, @RequestBody MechanicalPerformanceQueryDTOSecond dto) {

        // 查询力学性能数据
        List<SysMechanicalPerformance> agentList = sysMechanicalPerformanceService.queryMistedMechanicalPerformanceExportExcel(dto);
        // 获取地区信息，转换成 Map 以便后续使用
        List<Region> listRegion = regionService.list();
        Map<Integer, Region> regionMap = listRegion.stream()
                .collect(Collectors.toMap(Region::getId, Function.identity()));


        // 获取水泥信息，转换成 Map 以便后续使用
        List<SysCement> listCement = sysCementService.list();
        Map<Integer, SysCement> CementMap = listCement.stream()
                .collect(Collectors.toMap(SysCement::getCementId, Function.identity()));


        // 获取水泥信息，转换成 Map 以便后续使用
        List<SysStone> listStone = sysStoneService.list();
        Map<Integer, SysStone> StoneMap = listStone.stream()
                .collect(Collectors.toMap(SysStone::getStoneId, Function.identity()));


        // 获取砂信息，转换成 Map 以便后续使用
        List<SysSand> listSande = sysSandService.list();
        Map<Integer, SysSand> SandeMap = listSande.stream()
                .collect(Collectors.toMap(SysSand::getSandId, Function.identity()));


        // 获取石粉信息，转换成 Map 以便后续使用
        List<SysOtherAdmixtures> listOtherAdmixtures = sysOtherAdmixturesService.list();
        Map<Integer, SysOtherAdmixtures> OtherAdmixturesMap = listOtherAdmixtures.stream()
                .collect(Collectors.toMap(SysOtherAdmixtures::getAdmixturesId, Function.identity()));


        // 获取矿粉信息，转换成 Map 以便后续使用
        List<SysMineralPowder> listMineralPowder = sysMineralPowderService.list();
        Map<Integer, SysMineralPowder> SysMineralPowderMap = listMineralPowder.stream()
                .collect(Collectors.toMap(SysMineralPowder::getPowderId, Function.identity()));

        // 获取粉煤灰信息，转换成 Map 以便后续使用
        List<SysFlyash> listFlyash = sysFlyashService.list();
        Map<Integer, SysFlyash> flyashMap = listFlyash.stream()
                .collect(Collectors.toMap(SysFlyash::getFlyashId, Function.identity()));


        // 获取减水剂信息，转换成 Map 以便后续使用
        List<SysWaterReducer> listSysWaterReducer = sysWaterReducerService.list();
        Map<Integer, SysWaterReducer> SysWaterReducerMap = listSysWaterReducer.stream()
                .collect(Collectors.toMap(SysWaterReducer::getReducerId, Function.identity()));


        // 获取增效剂信息，转换成 Map 以便后续使用
        List<SysEfficiencyAgent> listEfficiencyAgent = sysEfficiencyAgent.list();
        Map<Integer, SysEfficiencyAgent> efficiencyAgentMap = listEfficiencyAgent.stream()
                .collect(Collectors.toMap(SysEfficiencyAgent::getAgentId, Function.identity()));


        // 获取膨胀剂信息，转换成 Map 以便后续使用
        List<SysSwellingagent> listSwellingagent = sysSwellingagentService.list();
        Map<Integer, SysSwellingagent> swellingagentMap = listSwellingagent.stream()
                .collect(Collectors.toMap(SysSwellingagent::getSwellingagentId, Function.identity()));


        // 准备返回的 VO 列表
        List<SysMechanicalPerformanceThirdVO> agentVOList = new ArrayList<>();
        for (SysMechanicalPerformance smp : agentList) {
            SysMechanicalPerformanceThirdVO vo = new SysMechanicalPerformanceThirdVO();
            BeanUtils.copyProperties(smp, vo);

            // 设置地区名称
            Integer regionId = smp.getRegion();
            Region region = regionMap.get(regionId);
            if (region != null) {
                vo.setRegionNameStr(region.getFullName());
            }

            LocalDateTime productionDate = smp.getProductionDate();
            if (productionDate != null) {
                vo.setProductionDate(productionDate);
            }


            //查询水泥数据
            Integer cementId = smp.getCementId();
            if (cementId != null) {
                SysCement sysCement = CementMap.get(cementId);
                if (sysCement != null) {
                    vo.setCementModel(sysCement.getModel());
                    vo.setCementCaoContent(sysCement.getCaoContent());
                    vo.setCementSio2Content(sysCement.getSio2Content());
                    vo.setCementAl2o3Content(sysCement.getAl2o3Content());
                    vo.setCementCompressiveStrength28d(sysCement.getCompressiveStrength28d());
                    vo.setCementStrengthGrade(sysCement.getStrengthGrade());
                    Integer regionName = sysCement.getRegionName();
                    if (regionName != null) {
                        Region region1 = regionMap.get(regionName);
                        if (region1 != null) {
                            vo.setCementRegionNameStr(region1.getFullName());
                        }

                    }
                }


            }


            //石头 5-10
            Integer stone510Id = smp.getStone510Id();
            if (stone510Id != null) {
                SysStone sysStone510 = StoneMap.get(stone510Id);
                if (sysStone510 != null) {
                    System.out.println("哈哈哈510" + sysStone510);
                    vo.setStoneModel510(sysStone510.getModel());
                    vo.setStoneSpecification510(sysStone510.getStoneSpecification());
                    vo.setStoneStackingDensity510(sysStone510.getStackingDensity());
                    vo.setStoneCompactDensity510(sysStone510.getCompactDensity());
                    vo.setStoneBulkdensity510(sysStone510.getBulkDensity());
                    Integer regionNameStone510 = sysStone510.getRegionName();
                    if (regionNameStone510 != null) {
                        Region region1 = regionMap.get(regionNameStone510);
                        if (region1 != null) {
                            vo.setStoneRegionNameStr510(region1.getFullName());
                        }
                    }
                }

            }

            //石头 5-25
            Integer stone525Id = smp.getStone525Id();
            if (stone525Id != null) {
                SysStone sysStone525 = StoneMap.get(stone525Id);
                if (sysStone525 != null) {
                    System.out.println("哈哈哈510" + sysStone525);
                    vo.setStoneModel525(sysStone525.getModel());
                    vo.setStoneSpecification525(sysStone525.getStoneSpecification());
                    vo.setStoneStackingDensity525(sysStone525.getStackingDensity());
                    vo.setStoneCompactDensity525(sysStone525.getCompactDensity());
                    vo.setStoneBulkdensity525(sysStone525.getBulkDensity());
                    Integer regionNameStone525 = sysStone525.getRegionName();
                    if (regionNameStone525 != null) {
                        Region region1 = regionMap.get(regionNameStone525);
                        if (region1 != null) {
                            vo.setStoneRegionNameStr525(region1.getFullName());
                        }
                    }
                }
            }


            //石头 2040
            Integer stone2040Id = smp.getStone525Id();
            if (stone2040Id != null) {
                SysStone sysStone2040 = StoneMap.get(stone2040Id);
                if (sysStone2040 != null) {
                    System.out.println("哈哈哈510" + sysStone2040);
                    vo.setStoneModel2040(sysStone2040.getModel());
                    vo.setStoneSpecification2040(sysStone2040.getStoneSpecification());
                    vo.setStoneStackingDensity2040(sysStone2040.getStackingDensity());
                    vo.setStoneCompactDensity2040(sysStone2040.getCompactDensity());
                    vo.setStoneBulkdensity2040(sysStone2040.getBulkDensity());
                    Integer regionNameStone2040 = sysStone2040.getRegionName();
                    if (regionNameStone2040 != null) {
                        Region region1 = regionMap.get(regionNameStone2040);
                        if (region1 != null) {
                            vo.setStoneRegionNameStr2040(region1.getFullName());
                        }
                    }
                }
            }


            //石头 10-20
            Integer stone1020Id = smp.getStone1020Id();
            if (stone1020Id != null) {
                SysStone sysStone1020 = StoneMap.get(stone1020Id);
                if (sysStone1020 != null) {
                    System.out.println("哈哈哈510" + sysStone1020);
                    vo.setStoneModel1020(sysStone1020.getModel());
                    vo.setStoneSpecification1020(sysStone1020.getStoneSpecification());
                    vo.setStoneStackingDensity1020(sysStone1020.getStackingDensity());
                    vo.setStoneCompactDensity1020(sysStone1020.getCompactDensity());
                    vo.setStoneBulkdensity1020(sysStone1020.getBulkDensity());
                    Integer regionNameStone1020 = sysStone1020.getRegionName();
                    if (regionNameStone1020 != null) {
                        Region region1 = regionMap.get(regionNameStone1020);
                        if (region1 != null) {
                            vo.setStoneRegionNameStr1020(region1.getFullName());
                        }
                    }
                }
            }


            //石头 10-30
            Integer stone1030Id = smp.getStone1030Id();
            if (stone1030Id != null) {
                SysStone sysStone1030 = StoneMap.get(stone1030Id);
                if (sysStone1030 != null) {
                    System.out.println("哈哈哈510" + sysStone1030);
                    vo.setStoneModel1030(sysStone1030.getModel());
                    vo.setStoneSpecification1030(sysStone1030.getStoneSpecification());
                    vo.setStoneStackingDensity1030(sysStone1030.getStackingDensity());
                    vo.setStoneCompactDensity1030(sysStone1030.getCompactDensity());
                    vo.setStoneBulkdensity1030(sysStone1030.getBulkDensity());
                    Integer regionNameStone1030 = sysStone1030.getRegionName();
                    if (regionNameStone1030 != null) {
                        Region region1 = regionMap.get(regionNameStone1030);
                        if (region1 != null) {
                            vo.setStoneRegionNameStr1030(region1.getFullName());
                        }
                    }
                }
            }

            vo.setStone2031(smp.getStoneCoarse20315());
            //石头 0-10
            Integer stone010Id = smp.getStone010Id();
            if (stone010Id != null) {
                SysStone sysStone010 = StoneMap.get(stone010Id);
                if (sysStone010 != null) {

                    vo.setStoneModel010(sysStone010.getModel());
                    vo.setStoneSpecification010(sysStone010.getStoneSpecification());
                    vo.setStoneStackingDensity010(sysStone010.getStackingDensity());
                    vo.setStoneCompactDensity010(sysStone010.getCompactDensity());
                    vo.setStoneBulkdensity010(sysStone010.getBulkDensity());
                    Integer regionNameStone010 = sysStone010.getRegionName();
                    if (regionNameStone010 != null) {
                        Region region1 = regionMap.get(regionNameStone010);
                        if (region1 != null) {
                            vo.setStoneRegionNameStr010(region1.getFullName());
                        }
                    }
                }
            }

            //石头 20-315
            Integer stone20315Id = smp.getStone2031Id();
            if (stone20315Id != null) {
                SysStone sysStone20315 = StoneMap.get(stone20315Id);
                if (sysStone20315 != null) {

                    vo.setStoneModel20315(sysStone20315.getModel());
                    vo.setStoneSpecification20315(sysStone20315.getStoneSpecification());
                    vo.setStoneStackingDensity20315(sysStone20315.getStackingDensity());
                    vo.setStoneCompactDensity20315(sysStone20315.getCompactDensity());
                    vo.setStoneBulkdensity20315(sysStone20315.getBulkDensity());
                    Integer regionNameStone20315 = sysStone20315.getRegionName();
                    if (regionNameStone20315 != null) {
                        Region region1 = regionMap.get(regionNameStone20315);
                        if (region1 != null) {
                            vo.setStoneRegionNameStr20315(region1.getFullName());
                        }
                    }
                }
            }


            //砂31-37
            vo.setSand3137(smp.getSandRiverCoarse3137());
            Integer sandRiverCoarse3137Id = smp.getSandRiverCoarse3137Id();
            if (sandRiverCoarse3137Id != null) {
                SysSand sysSand3137 = SandeMap.get(sandRiverCoarse3137Id);
                if (sysSand3137 != null) {
                    vo.setSandType3137(sysSand3137.getType());
                    vo.setSandFineness3137(sysSand3137.getFineness());
                    vo.setSandBulkDensity3137(sysSand3137.getBulkDensity());
                    vo.setSandCompactDensity3137(sysSand3137.getCompactDensity());
                    vo.setSandApparentDensity3137(sysSand3137.getApparentDensity());
                    vo.setSandParticleSizeDistribution3137(sysSand3137.getParticleSizeDistribution());
                    Integer regionName3137 = sysSand3137.getRegionName();
                    if (regionName3137 != null) {
                        Region region1 = regionMap.get(regionName3137);
                        if (region1 != null) {
                            vo.setSandRegionNameStr3137(region1.getFullName());
                        }
                    }


                }


            }


            //砂23-30
            vo.setSand2330(smp.getSandRiver2330Med());
            Integer sandRiverCoarse2330Id = smp.getSandRiver2330MedId();
            if (sandRiverCoarse2330Id != null) {
                SysSand sysSand2330 = SandeMap.get(sandRiverCoarse2330Id);
                if (sysSand2330 != null) {
                    vo.setSandType2330(sysSand2330.getType());
                    vo.setSandFineness2330(sysSand2330.getFineness());
                    vo.setSandBulkDensity2330(sysSand2330.getBulkDensity());
                    vo.setSandCompactDensity2330(sysSand2330.getCompactDensity());
                    vo.setSandApparentDensity2330(sysSand2330.getApparentDensity());
                    vo.setSandParticleSizeDistribution2330(sysSand2330.getParticleSizeDistribution());
                    Integer regionName2330 = sysSand2330.getRegionName();
                    if (regionName2330 != null) {
                        Region region1 = regionMap.get(regionName2330);
                        if (region1 != null) {
                            vo.setSandRegionNameStr2330(region1.getFullName());
                        }
                    }


                }


            }


            //砂16-22
            vo.setSand1622(smp.getSandRiver1622Fine());
            Integer sandRiverCoarse1622Id = smp.getSandRiver1622FineId();
            if (sandRiverCoarse1622Id != null) {
                SysSand sysSand1622 = SandeMap.get(sandRiverCoarse1622Id);
                if (sysSand1622 != null) {
                    vo.setSandType1622(sysSand1622.getType());
                    vo.setSandFineness1622(sysSand1622.getFineness());
                    vo.setSandBulkDensity1622(sysSand1622.getBulkDensity());
                    vo.setSandCompactDensity1622(sysSand1622.getCompactDensity());
                    vo.setSandApparentDensity1622(sysSand1622.getApparentDensity());
                    vo.setSandParticleSizeDistribution1622(sysSand1622.getParticleSizeDistribution());
                    Integer regionName1622 = sysSand1622.getRegionName();
                    if (regionName1622 != null) {
                        Region region1 = regionMap.get(regionName1622);
                        if (region1 != null) {
                            vo.setSandRegionNameStr1622(region1.getFullName());
                        }
                    }

                }

            }


            //砂2330B
            vo.setSand2330B(smp.getSandMech2330Med());
            Integer sandRiverCoarse2330BId = smp.getSandMech2330MedId();
            if (sandRiverCoarse2330BId != null) {
                SysSand sysSand2330B = SandeMap.get(sandRiverCoarse2330BId);
                if (sysSand2330B != null) {
                    vo.setSandType2330B(sysSand2330B.getType());
                    vo.setSandFineness2330B(sysSand2330B.getFineness());
                    vo.setSandBulkDensity2330B(sysSand2330B.getBulkDensity());
                    vo.setSandCompactDensity2330B(sysSand2330B.getCompactDensity());
                    vo.setSandApparentDensity2330B(sysSand2330B.getApparentDensity());
                    vo.setSandParticleSizeDistribution2330B(sysSand2330B.getParticleSizeDistribution());
                    Integer regionName2330B = sysSand2330B.getRegionName();
                    if (regionName2330B != null) {
                        Region region1 = regionMap.get(regionName2330B);
                        if (region1 != null) {
                            vo.setSandRegionNameStr2330B(region1.getFullName());
                        }
                    }

                }

            }


            //砂31-37B
            vo.setSand3137B(smp.getSandMech3137Coarse());
            Integer sandRiverCoarse3137BId = smp.getSandMech3137CoarseId();
            if (sandRiverCoarse3137BId != null) {
                SysSand sysSand3137B = SandeMap.get(sandRiverCoarse3137BId);
                if (sysSand3137B != null) {
                    vo.setSandType3137B(sysSand3137B.getType());
                    vo.setSandFineness3137B(sysSand3137B.getFineness());
                    vo.setSandBulkDensity3137B(sysSand3137B.getBulkDensity());
                    vo.setSandCompactDensity3137B(sysSand3137B.getCompactDensity());
                    vo.setSandApparentDensity3137B(sysSand3137B.getApparentDensity());
                    vo.setSandParticleSizeDistribution3137B(sysSand3137B.getParticleSizeDistribution());
                    Integer regionName3137B = sysSand3137B.getRegionName();
                    if (regionName3137B != null) {
                        Region region1 = regionMap.get(regionName3137B);
                        if (region1 != null) {
                            vo.setSandRegionNameStr3137B(region1.getFullName());
                        }
                    }

                }
            }


            //砂16-22
            vo.setSand1622B(smp.getSandMech1622Fine());
            Integer sandRiverCoarse1622BId = smp.getSandMech1622FineId();
            if (sandRiverCoarse1622BId != null) {
                SysSand sysSand1622B = SandeMap.get(sandRiverCoarse1622BId);
                if (sysSand1622B != null) {
                    vo.setSandType1622B(sysSand1622B.getType());
                    vo.setSandFineness1622B(sysSand1622B.getFineness());
                    vo.setSandBulkDensity1622B(sysSand1622B.getBulkDensity());
                    vo.setSandCompactDensity1622B(sysSand1622B.getCompactDensity());
                    vo.setSandApparentDensity1622B(sysSand1622B.getApparentDensity());
                    vo.setSandParticleSizeDistribution1622B(sysSand1622B.getParticleSizeDistribution());
                    Integer regionName1622B = sysSand1622B.getRegionName();
                    if (regionName1622B != null) {
                        Region region1 = regionMap.get(regionName1622B);
                        if (region1 != null) {
                            vo.setSandRegionNameStr1622B(region1.getFullName());
                        }
                    }

                }

            }


            //砂04-75
            vo.setSand0475(smp.getSandMech0475());
            Integer sandRiverCoarse0475Id = smp.getSandMech0475Id();
            if (sandRiverCoarse0475Id != null) {
                SysSand sysSand0475 = SandeMap.get(sandRiverCoarse0475Id);
                if (sysSand0475 != null) {
                    vo.setSandType0475(sysSand0475.getType());
                    vo.setSandFineness0475(sysSand0475.getFineness());
                    vo.setSandBulkDensity0475(sysSand0475.getBulkDensity());
                    vo.setSandCompactDensity0475(sysSand0475.getCompactDensity());
                    vo.setSandApparentDensity0475(sysSand0475.getApparentDensity());
                    vo.setSandParticleSizeDistribution0475(sysSand0475.getParticleSizeDistribution());
                    Integer regionName0475 = sysSand0475.getRegionName();
                    if (regionName0475 != null) {
                        Region region1 = regionMap.get(regionName0475);
                        if (region1 != null) {
                            vo.setSandRegionNameStr0475(region1.getFullName());
                        }
                    }

                }
            }

//砂0-9
            vo.setSand09(smp.getSandMech09());
            Integer sandRiverCoarse09Id = smp.getSandMech09Id();
            if (sandRiverCoarse09Id != null) {
                SysSand sysSand09 = SandeMap.get(sandRiverCoarse09Id);
                if (sysSand09 != null) {
                    vo.setSandType09(sysSand09.getType());
                    vo.setSandFineness09(sysSand09.getFineness());
                    vo.setSandBulkDensity09(sysSand09.getBulkDensity());
                    vo.setSandCompactDensity09(sysSand09.getCompactDensity());
                    vo.setSandApparentDensity09(sysSand09.getApparentDensity());
                    vo.setSandParticleSizeDistribution09(sysSand09.getParticleSizeDistribution());
                    Integer regionName09 = sysSand09.getRegionName();
                    if (regionName09 != null) {
                        Region region1 = regionMap.get(regionName09);
                        if (region1 != null) {
                            vo.setSandRegionNameStr09(region1.getFullName());
                        }
                    }

                }
            }


            //石粉
            vo.setAdmixtures(smp.getStonePowder());
            Integer stonePowderId = smp.getStonePowderId();
            if (stonePowderId != null) {
                SysOtherAdmixtures sysOtherAdmixtures = OtherAdmixturesMap.get(stonePowderId);
                if (sysOtherAdmixtures != null) {
                    vo.setAdmixturesModel(sysOtherAdmixtures.getModel());
                    vo.setAdmixturesFineness(sysOtherAdmixtures.getFineness());
                    vo.setAdmixturesMoistureContent(sysOtherAdmixtures.getMoistureContent());
                    vo.setAdmixturesActivityIndex28d(sysOtherAdmixtures.getActivityIndex28d());
                    Integer regionName09 = sysOtherAdmixtures.getRegionName();
                    if (regionName09 != null) {
                        Region region1 = regionMap.get(regionName09);
                        if (region1 != null) {
                            vo.setAdmixturesRegionNameStr(region1.getFullName());
                        }
                    }

                }
            }


            //矿粉
            vo.setMineralPowder(smp.getMineralPowder());
            Integer mineralPowderId = smp.getMineralPowderId();
            if (mineralPowderId != null) {
                SysMineralPowder sysMineralPowder = SysMineralPowderMap.get(mineralPowderId);
                if (sysMineralPowder != null) {
                    vo.setMineralModel(sysMineralPowder.getModel());
                    vo.setMineralSlagGrade(sysMineralPowder.getSlagGrade());
                    vo.setMineralFineness(sysMineralPowder.getFineness());
                    vo.setMineralMoistureContent(sysMineralPowder.getMoistureContent());
                    vo.setMineralActivityIndex28d(sysMineralPowder.getActivityIndex28d());

                    Integer regionName = sysMineralPowder.getRegionName();
                    if (regionName != null) {
                        Region region1 = regionMap.get(regionName);
                        if (region1 != null) {
                            vo.setMineralRegionNameStr(region1.getFullName());
                        }
                    }

                }
            }


            //粉煤灰
            vo.setFlyash(smp.getFlyAsh());
            Integer flyAshId = smp.getFlyAshId();
            if (flyAshId != null) {
                SysFlyash sysFlyash = flyashMap.get(flyAshId);
                if (sysFlyash != null) {
                    vo.setFlyashGrade(sysFlyash.getGrade());
                    vo.setFlyashFactoryGrade(sysFlyash.getFactoryGrade());
                    vo.setFlyashFineness(sysFlyash.getFineness());
                    vo.setFlyashMoistureContent(sysFlyash.getMoistureContent());
                    vo.setFlyashActivityIndex28d(sysFlyash.getActivityIndex28d());

                    Integer regionName = sysFlyash.getRegionName();
                    if (regionName != null) {
                        Region region1 = regionMap.get(regionName);
                        if (region1 != null) {
                            vo.setFlyashRegionNameStr(region1.getFullName());
                        }
                    }

                }
            }


            //减水剂

            vo.setReducer(smp.getWaterReducer());
            Integer waterReducerId = smp.getWaterReducerId();
            if (waterReducerId != null) {
                SysWaterReducer sysWaterReducer = SysWaterReducerMap.get(waterReducerId);
                if (sysWaterReducer != null) {
                    vo.setReducerModel(sysWaterReducer.getModel());
                    vo.setReducerSolidContent(sysWaterReducer.getSolidContent());
                    vo.setReducerCementPsteFlow(sysWaterReducer.getCementPasteFlow());
                    vo.setReducerReducingRate(sysWaterReducer.getReducingRate());
                    vo.setReducerRegionNameStr(sysWaterReducer.getSourceName());

                }
            }


            //增效剂
            vo.setEfficiencyAgentAgent(smp.getEfficiencyAgent());
            Integer efficiencyAgentId = smp.getEfficiencyAgentId();
            if (efficiencyAgentId != null) {
                SysEfficiencyAgent efficiencyAgent = efficiencyAgentMap.get(efficiencyAgentId);
                if (efficiencyAgent != null) {
                    vo.setEfficiencyAgentModel(efficiencyAgent.getModel());
                    vo.setEfficiencyAgentSourceName(efficiencyAgent.getSourceName());
                }
            }


            //膨胀剂
            vo.setSwellingAgent(smp.getExpansionAgent());
            Integer swellingAgentId = smp.getExpansionAgentId();
            if (swellingAgentId != null) {
                SysSwellingagent sysSwellingagent = swellingagentMap.get(swellingAgentId);
                if (sysSwellingagent != null) {
                    vo.setSwellingagentModel(sysSwellingagent.getModel());
                    vo.setSwellingagentSourceName(sysSwellingagent.getSourceName());

                }
            }


            agentVOList.add(vo);
        }
        System.out.println("膨胀剂数据：" + agentList);

        // 导出 Excel
        ExcelUtil<SysMechanicalPerformanceThirdVO> util = new ExcelUtil<>(SysMechanicalPerformanceThirdVO.class);
        util.exportExcel(response, agentVOList, "力学性能数据导出");

    }






//    @PostMapping("queryMistedMechanicalPerformance")
//    public AjaxResult queryMistedMechanicalPerformanceSecond(@RequestBody MechanicalPerformanceQueryDTOSecond dto) {
//        try {
//            int pageNum = dto.getPageNum() == null ? 1 : dto.getPageNum();
//            int pageSize = dto.getPageSize() == null ? 10 : dto.getPageSize();
//
//            PageHelper.startPage(pageNum, pageSize);
//            List<MechanicalPerformanceQueryVOSecond> list = mechanicalPerformanceService.queryMistedMechanicalPerformanceSecond(dto);
//
//            // 用PageInfo获取分页信息
//            PageInfo<MechanicalPerformanceQueryVOSecond> pageInfo = new PageInfo<>(list);
//
//            // 自定义一个Map封装所有返回字段
//            Map<String, Object> resMap = new HashMap<>();
//            resMap.put("data", list);
//            resMap.put("total", pageInfo.getTotal());
//            resMap.put("pageNum", pageNum);
//            resMap.put("pageSize", pageSize);
//
//            // 这里调用AjaxResult.success(Object data)默认只返回data，
//            // 所以我们需要调用它的构造方法或自定义静态方法来返回更多字段
//
//            // 自定义一个AjaxResult，支持扩展字段：
//            return AjaxResult.success("操作成功", resMap);
//
//        } catch (Exception e) {
//            return AjaxResult.error("请求异常");
//        }
//    }


//    @PostMapping("queryMistedMechanicalPerformance")
//    public AjaxResult queryMistedMechanicalPerformanceSecond(@RequestBody MechanicalPerformanceQueryDTOSecond mechanicalPerformanceQueryDTOSecond) {
//        // 调用服务层获取查询结果
//        List<MechanicalPerformanceQueryVOSecond> result = null;
//        try {
//            startPage(); // 启动分页
//            result = mechanicalPerformanceService.queryMistedMechanicalPerformanceSecond(mechanicalPerformanceQueryDTOSecond);
//        } catch (Exception e) {
//            return AjaxResult.error("请求异常");
//        }
//
//        // 返回结果
//        return AjaxResult.success(result);
//    }


    /**
     * 查询 坍落度表
     *
     * @param
     * @return
     */


    @PostMapping("/querSysSlumpy")
    public PageResponse<SysSlumpVO> querSysSlumpy(@RequestBody SysSlumpDTO sysSlumpDTO) {
        int pageNum = sysSlumpDTO.getPageNum() == null ? 1 : sysSlumpDTO.getPageNum();
        int pageSize = sysSlumpDTO.getPageSize() == null ? 10 : sysSlumpDTO.getPageSize();
        PageHelper.startPage(pageNum, pageSize);
        List<SysSlumpVO> list = sysSlumpService.querSysSlumpy(sysSlumpDTO);
        PageInfo<SysSlumpVO> pageInfo = new PageInfo<>(list);

        return new PageResponse<>(200, "操作成功", pageInfo.getTotal(), pageNum, pageSize, list);
    }






    @PostMapping("/querSysSlumpyExportExcel")
    public void querSysSlumpyExportExcel(HttpServletResponse response, @RequestBody SysSlumpDTO sysSlumpDTO) {
        // 查询力学性能数据
        List<SysSlump> agentList = sysSlumpService.querSysSlumpyExportExcel(sysSlumpDTO);
        // 获取地区信息，转换成 Map 以便后续使用
        List<Region> listRegion = regionService.list();
        Map<Integer, Region> regionMap = listRegion.stream()
                .collect(Collectors.toMap(Region::getId, Function.identity()));


        // 获取水泥信息，转换成 Map 以便后续使用
        List<SysCement> listCement = sysCementService.list();
        Map<Integer, SysCement> CementMap = listCement.stream()
                .collect(Collectors.toMap(SysCement::getCementId, Function.identity()));


        // 获取水泥信息，转换成 Map 以便后续使用
        List<SysStone> listStone = sysStoneService.list();
        Map<Integer, SysStone> StoneMap = listStone.stream()
                .collect(Collectors.toMap(SysStone::getStoneId, Function.identity()));


        // 获取砂信息，转换成 Map 以便后续使用
        List<SysSand> listSande = sysSandService.list();
        Map<Integer, SysSand> SandeMap = listSande.stream()
                .collect(Collectors.toMap(SysSand::getSandId, Function.identity()));


        // 获取石粉信息，转换成 Map 以便后续使用
        List<SysOtherAdmixtures> listOtherAdmixtures = sysOtherAdmixturesService.list();
        Map<Integer, SysOtherAdmixtures> OtherAdmixturesMap = listOtherAdmixtures.stream()
                .collect(Collectors.toMap(SysOtherAdmixtures::getAdmixturesId, Function.identity()));


        // 获取矿粉信息，转换成 Map 以便后续使用
        List<SysMineralPowder> listMineralPowder = sysMineralPowderService.list();
        Map<Integer, SysMineralPowder> SysMineralPowderMap = listMineralPowder.stream()
                .collect(Collectors.toMap(SysMineralPowder::getPowderId, Function.identity()));

        // 获取粉煤灰信息，转换成 Map 以便后续使用
        List<SysFlyash> listFlyash = sysFlyashService.list();
        Map<Integer, SysFlyash> flyashMap = listFlyash.stream()
                .collect(Collectors.toMap(SysFlyash::getFlyashId, Function.identity()));


        // 获取减水剂信息，转换成 Map 以便后续使用
        List<SysWaterReducer> listSysWaterReducer = sysWaterReducerService.list();
        Map<Integer, SysWaterReducer> SysWaterReducerMap = listSysWaterReducer.stream()
                .collect(Collectors.toMap(SysWaterReducer::getReducerId, Function.identity()));


        // 获取增效剂信息，转换成 Map 以便后续使用
        List<SysEfficiencyAgent> listEfficiencyAgent = sysEfficiencyAgent.list();
        Map<Integer, SysEfficiencyAgent> efficiencyAgentMap = listEfficiencyAgent.stream()
                .collect(Collectors.toMap(SysEfficiencyAgent::getAgentId, Function.identity()));


        // 获取膨胀剂信息，转换成 Map 以便后续使用
        List<SysSwellingagent> listSwellingagent = sysSwellingagentService.list();
        Map<Integer, SysSwellingagent> swellingagentMap = listSwellingagent.stream()
                .collect(Collectors.toMap(SysSwellingagent::getSwellingagentId, Function.identity()));


        // 准备返回的 VO 列表
        List<SysMechanicalPerformanceFourthVO> agentVOList = new ArrayList<>();
        for (SysSlump smp : agentList) {
            SysMechanicalPerformanceFourthVO vo = new SysMechanicalPerformanceFourthVO();
            BeanUtils.copyProperties(smp, vo);

            // 设置地区名称
            Integer regionId = smp.getRegion();
            Region region = regionMap.get(regionId);
            if (region != null) {
                vo.setRegionNameStr(region.getFullName());
            }

            LocalDateTime productionDate = smp.getProductionDate();
            if (productionDate != null) {
                vo.setProductionDate(productionDate);
            }
            BigDecimal slump = smp.getSlump();
            vo.setStrengthGrade(slump);

            //查询水泥数据
            Integer cementId = smp.getCementId();
            if (cementId != null) {
                SysCement sysCement = CementMap.get(cementId);
                if (sysCement != null) {
                    vo.setCementModel(sysCement.getModel());
                    vo.setCementCaoContent(sysCement.getCaoContent());
                    vo.setCementSio2Content(sysCement.getSio2Content());
                    vo.setCementAl2o3Content(sysCement.getAl2o3Content());
                    vo.setCementCompressiveStrength28d(sysCement.getCompressiveStrength28d());
                    vo.setCementStrengthGrade(sysCement.getStrengthGrade());
                    Integer regionName = sysCement.getRegionName();
                    if (regionName != null) {
                        Region region1 = regionMap.get(regionName);
                        if (region1 != null) {
                            vo.setCementRegionNameStr(region1.getFullName());
                        }

                    }
                }


            }


            //石头 5-10
            Integer stone510Id = smp.getStone510Id();
            if (stone510Id != null) {
                SysStone sysStone510 = StoneMap.get(stone510Id);
                if (sysStone510 != null) {
                    System.out.println("哈哈哈510" + sysStone510);
                    vo.setStoneModel510(sysStone510.getModel());
                    vo.setStoneSpecification510(sysStone510.getStoneSpecification());
                    vo.setStoneStackingDensity510(sysStone510.getStackingDensity());
                    vo.setStoneCompactDensity510(sysStone510.getCompactDensity());
                    vo.setStoneBulkdensity510(sysStone510.getBulkDensity());
                    Integer regionNameStone510 = sysStone510.getRegionName();
                    if (regionNameStone510 != null) {
                        Region region1 = regionMap.get(regionNameStone510);
                        if (region1 != null) {
                            vo.setStoneRegionNameStr510(region1.getFullName());
                        }
                    }
                }

            }

            //石头 5-25
            Integer stone525Id = smp.getStone525Id();
            if (stone525Id != null) {
                SysStone sysStone525 = StoneMap.get(stone525Id);
                if (sysStone525 != null) {
                    System.out.println("哈哈哈510" + sysStone525);
                    vo.setStoneModel525(sysStone525.getModel());
                    vo.setStoneSpecification525(sysStone525.getStoneSpecification());
                    vo.setStoneStackingDensity525(sysStone525.getStackingDensity());
                    vo.setStoneCompactDensity525(sysStone525.getCompactDensity());
                    vo.setStoneBulkdensity525(sysStone525.getBulkDensity());
                    Integer regionNameStone525 = sysStone525.getRegionName();
                    if (regionNameStone525 != null) {
                        Region region1 = regionMap.get(regionNameStone525);
                        if (region1 != null) {
                            vo.setStoneRegionNameStr525(region1.getFullName());
                        }
                    }
                }
            }


            //石头 2040
            Integer stone2040Id = smp.getStone525Id();
            if (stone2040Id != null) {
                SysStone sysStone2040 = StoneMap.get(stone2040Id);
                if (sysStone2040 != null) {
                    System.out.println("哈哈哈510" + sysStone2040);
                    vo.setStoneModel2040(sysStone2040.getModel());
                    vo.setStoneSpecification2040(sysStone2040.getStoneSpecification());
                    vo.setStoneStackingDensity2040(sysStone2040.getStackingDensity());
                    vo.setStoneCompactDensity2040(sysStone2040.getCompactDensity());
                    vo.setStoneBulkdensity2040(sysStone2040.getBulkDensity());
                    Integer regionNameStone2040 = sysStone2040.getRegionName();
                    if (regionNameStone2040 != null) {
                        Region region1 = regionMap.get(regionNameStone2040);
                        if (region1 != null) {
                            vo.setStoneRegionNameStr2040(region1.getFullName());
                        }
                    }
                }
            }


            //石头 10-20
            Integer stone1020Id = smp.getStone1020Id();
            if (stone1020Id != null) {
                SysStone sysStone1020 = StoneMap.get(stone1020Id);
                if (sysStone1020 != null) {
                    System.out.println("哈哈哈510" + sysStone1020);
                    vo.setStoneModel1020(sysStone1020.getModel());
                    vo.setStoneSpecification1020(sysStone1020.getStoneSpecification());
                    vo.setStoneStackingDensity1020(sysStone1020.getStackingDensity());
                    vo.setStoneCompactDensity1020(sysStone1020.getCompactDensity());
                    vo.setStoneBulkdensity1020(sysStone1020.getBulkDensity());
                    Integer regionNameStone1020 = sysStone1020.getRegionName();
                    if (regionNameStone1020 != null) {
                        Region region1 = regionMap.get(regionNameStone1020);
                        if (region1 != null) {
                            vo.setStoneRegionNameStr1020(region1.getFullName());
                        }
                    }
                }
            }


            //石头 10-30
            Integer stone1030Id = smp.getStone1030Id();
            if (stone1030Id != null) {
                SysStone sysStone1030 = StoneMap.get(stone1030Id);
                if (sysStone1030 != null) {
                    System.out.println("哈哈哈510" + sysStone1030);
                    vo.setStoneModel1030(sysStone1030.getModel());
                    vo.setStoneSpecification1030(sysStone1030.getStoneSpecification());
                    vo.setStoneStackingDensity1030(sysStone1030.getStackingDensity());
                    vo.setStoneCompactDensity1030(sysStone1030.getCompactDensity());
                    vo.setStoneBulkdensity1030(sysStone1030.getBulkDensity());
                    Integer regionNameStone1030 = sysStone1030.getRegionName();
                    if (regionNameStone1030 != null) {
                        Region region1 = regionMap.get(regionNameStone1030);
                        if (region1 != null) {
                            vo.setStoneRegionNameStr1030(region1.getFullName());
                        }
                    }
                }
            }

            vo.setStone2031(smp.getStoneCoarse20315());
            //石头 0-10
            Integer stone010Id = smp.getStone010Id();
            if (stone010Id != null) {
                SysStone sysStone010 = StoneMap.get(stone010Id);
                if (sysStone010 != null) {

                    vo.setStoneModel010(sysStone010.getModel());
                    vo.setStoneSpecification010(sysStone010.getStoneSpecification());
                    vo.setStoneStackingDensity010(sysStone010.getStackingDensity());
                    vo.setStoneCompactDensity010(sysStone010.getCompactDensity());
                    vo.setStoneBulkdensity010(sysStone010.getBulkDensity());
                    Integer regionNameStone010 = sysStone010.getRegionName();
                    if (regionNameStone010 != null) {
                        Region region1 = regionMap.get(regionNameStone010);
                        if (region1 != null) {
                            vo.setStoneRegionNameStr010(region1.getFullName());
                        }
                    }
                }
            }

            //石头 20-315
            Integer stone20315Id = smp.getStone2031Id();
            if (stone20315Id != null) {
                SysStone sysStone20315 = StoneMap.get(stone20315Id);
                if (sysStone20315 != null) {

                    vo.setStoneModel20315(sysStone20315.getModel());
                    vo.setStoneSpecification20315(sysStone20315.getStoneSpecification());
                    vo.setStoneStackingDensity20315(sysStone20315.getStackingDensity());
                    vo.setStoneCompactDensity20315(sysStone20315.getCompactDensity());
                    vo.setStoneBulkdensity20315(sysStone20315.getBulkDensity());
                    Integer regionNameStone20315 = sysStone20315.getRegionName();
                    if (regionNameStone20315 != null) {
                        Region region1 = regionMap.get(regionNameStone20315);
                        if (region1 != null) {
                            vo.setStoneRegionNameStr20315(region1.getFullName());
                        }
                    }
                }
            }


            //砂31-37
            vo.setSand3137(smp.getSandRiverCoarse3137());
            Integer sandRiverCoarse3137Id = smp.getSandRiverCoarse3137Id();
            if (sandRiverCoarse3137Id != null) {
                SysSand sysSand3137 = SandeMap.get(sandRiverCoarse3137Id);
                if (sysSand3137 != null) {
                    vo.setSandType3137(sysSand3137.getType());
                    vo.setSandFineness3137(sysSand3137.getFineness());
                    vo.setSandBulkDensity3137(sysSand3137.getBulkDensity());
                    vo.setSandCompactDensity3137(sysSand3137.getCompactDensity());
                    vo.setSandApparentDensity3137(sysSand3137.getApparentDensity());
                    vo.setSandParticleSizeDistribution3137(sysSand3137.getParticleSizeDistribution());
                    Integer regionName3137 = sysSand3137.getRegionName();
                    if (regionName3137 != null) {
                        Region region1 = regionMap.get(regionName3137);
                        if (region1 != null) {
                            vo.setSandRegionNameStr3137(region1.getFullName());
                        }
                    }


                }


            }


            //砂23-30
            vo.setSand2330(smp.getSandRiver2330Med());
            Integer sandRiverCoarse2330Id = smp.getSandRiver2330MedId();
            if (sandRiverCoarse2330Id != null) {
                SysSand sysSand2330 = SandeMap.get(sandRiverCoarse2330Id);
                if (sysSand2330 != null) {
                    vo.setSandType2330(sysSand2330.getType());
                    vo.setSandFineness2330(sysSand2330.getFineness());
                    vo.setSandBulkDensity2330(sysSand2330.getBulkDensity());
                    vo.setSandCompactDensity2330(sysSand2330.getCompactDensity());
                    vo.setSandApparentDensity2330(sysSand2330.getApparentDensity());
                    vo.setSandParticleSizeDistribution2330(sysSand2330.getParticleSizeDistribution());
                    Integer regionName2330 = sysSand2330.getRegionName();
                    if (regionName2330 != null) {
                        Region region1 = regionMap.get(regionName2330);
                        if (region1 != null) {
                            vo.setSandRegionNameStr2330(region1.getFullName());
                        }
                    }


                }


            }


            //砂16-22
            vo.setSand1622(smp.getSandRiver1622Fine());
            Integer sandRiverCoarse1622Id = smp.getSandRiver1622FineId();
            if (sandRiverCoarse1622Id != null) {
                SysSand sysSand1622 = SandeMap.get(sandRiverCoarse1622Id);
                if (sysSand1622 != null) {
                    vo.setSandType1622(sysSand1622.getType());
                    vo.setSandFineness1622(sysSand1622.getFineness());
                    vo.setSandBulkDensity1622(sysSand1622.getBulkDensity());
                    vo.setSandCompactDensity1622(sysSand1622.getCompactDensity());
                    vo.setSandApparentDensity1622(sysSand1622.getApparentDensity());
                    vo.setSandParticleSizeDistribution1622(sysSand1622.getParticleSizeDistribution());
                    Integer regionName1622 = sysSand1622.getRegionName();
                    if (regionName1622 != null) {
                        Region region1 = regionMap.get(regionName1622);
                        if (region1 != null) {
                            vo.setSandRegionNameStr1622(region1.getFullName());
                        }
                    }

                }

            }


            //砂2330B
            vo.setSand2330B(smp.getSandMech2330Med());
            Integer sandRiverCoarse2330BId = smp.getSandMech2330MedId();
            if (sandRiverCoarse2330BId != null) {
                SysSand sysSand2330B = SandeMap.get(sandRiverCoarse2330BId);
                if (sysSand2330B != null) {
                    vo.setSandType2330B(sysSand2330B.getType());
                    vo.setSandFineness2330B(sysSand2330B.getFineness());
                    vo.setSandBulkDensity2330B(sysSand2330B.getBulkDensity());
                    vo.setSandCompactDensity2330B(sysSand2330B.getCompactDensity());
                    vo.setSandApparentDensity2330B(sysSand2330B.getApparentDensity());
                    vo.setSandParticleSizeDistribution2330B(sysSand2330B.getParticleSizeDistribution());
                    Integer regionName2330B = sysSand2330B.getRegionName();
                    if (regionName2330B != null) {
                        Region region1 = regionMap.get(regionName2330B);
                        if (region1 != null) {
                            vo.setSandRegionNameStr2330B(region1.getFullName());
                        }
                    }

                }

            }


            //砂31-37B
            vo.setSand3137B(smp.getSandMech3137Coarse());
            Integer sandRiverCoarse3137BId = smp.getSandMech3137CoarseId();
            if (sandRiverCoarse3137BId != null) {
                SysSand sysSand3137B = SandeMap.get(sandRiverCoarse3137BId);
                if (sysSand3137B != null) {
                    vo.setSandType3137B(sysSand3137B.getType());
                    vo.setSandFineness3137B(sysSand3137B.getFineness());
                    vo.setSandBulkDensity3137B(sysSand3137B.getBulkDensity());
                    vo.setSandCompactDensity3137B(sysSand3137B.getCompactDensity());
                    vo.setSandApparentDensity3137B(sysSand3137B.getApparentDensity());
                    vo.setSandParticleSizeDistribution3137B(sysSand3137B.getParticleSizeDistribution());
                    Integer regionName3137B = sysSand3137B.getRegionName();
                    if (regionName3137B != null) {
                        Region region1 = regionMap.get(regionName3137B);
                        if (region1 != null) {
                            vo.setSandRegionNameStr3137B(region1.getFullName());
                        }
                    }

                }
            }


            //砂16-22
            vo.setSand1622B(smp.getSandMech1622Fine());
            Integer sandRiverCoarse1622BId = smp.getSandMech1622FineId();
            if (sandRiverCoarse1622BId != null) {
                SysSand sysSand1622B = SandeMap.get(sandRiverCoarse1622BId);
                if (sysSand1622B != null) {
                    vo.setSandType1622B(sysSand1622B.getType());
                    vo.setSandFineness1622B(sysSand1622B.getFineness());
                    vo.setSandBulkDensity1622B(sysSand1622B.getBulkDensity());
                    vo.setSandCompactDensity1622B(sysSand1622B.getCompactDensity());
                    vo.setSandApparentDensity1622B(sysSand1622B.getApparentDensity());
                    vo.setSandParticleSizeDistribution1622B(sysSand1622B.getParticleSizeDistribution());
                    Integer regionName1622B = sysSand1622B.getRegionName();
                    if (regionName1622B != null) {
                        Region region1 = regionMap.get(regionName1622B);
                        if (region1 != null) {
                            vo.setSandRegionNameStr1622B(region1.getFullName());
                        }
                    }

                }

            }


            //砂04-75
            vo.setSand0475(smp.getSandMech0475());
            Integer sandRiverCoarse0475Id = smp.getSandMech0475Id();
            if (sandRiverCoarse0475Id != null) {
                SysSand sysSand0475 = SandeMap.get(sandRiverCoarse0475Id);
                if (sysSand0475 != null) {
                    vo.setSandType0475(sysSand0475.getType());
                    vo.setSandFineness0475(sysSand0475.getFineness());
                    vo.setSandBulkDensity0475(sysSand0475.getBulkDensity());
                    vo.setSandCompactDensity0475(sysSand0475.getCompactDensity());
                    vo.setSandApparentDensity0475(sysSand0475.getApparentDensity());
                    vo.setSandParticleSizeDistribution0475(sysSand0475.getParticleSizeDistribution());
                    Integer regionName0475 = sysSand0475.getRegionName();
                    if (regionName0475 != null) {
                        Region region1 = regionMap.get(regionName0475);
                        if (region1 != null) {
                            vo.setSandRegionNameStr0475(region1.getFullName());
                        }
                    }

                }
            }

//砂0-9
            vo.setSand09(smp.getSandMech09());
            Integer sandRiverCoarse09Id = smp.getSandMech09Id();
            if (sandRiverCoarse09Id != null) {
                SysSand sysSand09 = SandeMap.get(sandRiverCoarse09Id);
                if (sysSand09 != null) {
                    vo.setSandType09(sysSand09.getType());
                    vo.setSandFineness09(sysSand09.getFineness());
                    vo.setSandBulkDensity09(sysSand09.getBulkDensity());
                    vo.setSandCompactDensity09(sysSand09.getCompactDensity());
                    vo.setSandApparentDensity09(sysSand09.getApparentDensity());
                    vo.setSandParticleSizeDistribution09(sysSand09.getParticleSizeDistribution());
                    Integer regionName09 = sysSand09.getRegionName();
                    if (regionName09 != null) {
                        Region region1 = regionMap.get(regionName09);
                        if (region1 != null) {
                            vo.setSandRegionNameStr09(region1.getFullName());
                        }
                    }

                }
            }


            //石粉
            vo.setAdmixtures(smp.getStonePowder());
            Integer stonePowderId = smp.getStonePowderId();
            if (stonePowderId != null) {
                SysOtherAdmixtures sysOtherAdmixtures = OtherAdmixturesMap.get(stonePowderId);
                if (sysOtherAdmixtures != null) {
                    vo.setAdmixturesModel(sysOtherAdmixtures.getModel());
                    vo.setAdmixturesFineness(sysOtherAdmixtures.getFineness());
                    vo.setAdmixturesMoistureContent(sysOtherAdmixtures.getMoistureContent());
                    vo.setAdmixturesActivityIndex28d(sysOtherAdmixtures.getActivityIndex28d());
                    Integer regionName09 = sysOtherAdmixtures.getRegionName();
                    if (regionName09 != null) {
                        Region region1 = regionMap.get(regionName09);
                        if (region1 != null) {
                            vo.setAdmixturesRegionNameStr(region1.getFullName());
                        }
                    }

                }
            }


            //矿粉
            vo.setMineralPowder(smp.getMineralPowder());
            Integer mineralPowderId = smp.getMineralPowderId();
            if (mineralPowderId != null) {
                SysMineralPowder sysMineralPowder = SysMineralPowderMap.get(mineralPowderId);
                if (sysMineralPowder != null) {
                    vo.setMineralModel(sysMineralPowder.getModel());
                    vo.setMineralSlagGrade(sysMineralPowder.getSlagGrade());
                    vo.setMineralFineness(sysMineralPowder.getFineness());
                    vo.setMineralMoistureContent(sysMineralPowder.getMoistureContent());
                    vo.setMineralActivityIndex28d(sysMineralPowder.getActivityIndex28d());

                    Integer regionName = sysMineralPowder.getRegionName();
                    if (regionName != null) {
                        Region region1 = regionMap.get(regionName);
                        if (region1 != null) {
                            vo.setMineralRegionNameStr(region1.getFullName());
                        }
                    }

                }
            }


            //粉煤灰
            vo.setFlyash(smp.getFlyAsh());
            Integer flyAshId = smp.getFlyAshId();
            if (flyAshId != null) {
                SysFlyash sysFlyash = flyashMap.get(flyAshId);
                if (sysFlyash != null) {
                    vo.setFlyashGrade(sysFlyash.getGrade());
                    vo.setFlyashFactoryGrade(sysFlyash.getFactoryGrade());
                    vo.setFlyashFineness(sysFlyash.getFineness());
                    vo.setFlyashMoistureContent(sysFlyash.getMoistureContent());
                    vo.setFlyashActivityIndex28d(sysFlyash.getActivityIndex28d());

                    Integer regionName = sysFlyash.getRegionName();
                    if (regionName != null) {
                        Region region1 = regionMap.get(regionName);
                        if (region1 != null) {
                            vo.setFlyashRegionNameStr(region1.getFullName());
                        }
                    }

                }
            }


            //减水剂

            vo.setReducer(smp.getWaterReducer());
            Integer waterReducerId = smp.getWaterReducerId();
            if (waterReducerId != null) {
                SysWaterReducer sysWaterReducer = SysWaterReducerMap.get(waterReducerId);
                if (sysWaterReducer != null) {
                    vo.setReducerModel(sysWaterReducer.getModel());
                    vo.setReducerSolidContent(sysWaterReducer.getSolidContent());
                    vo.setReducerCementPsteFlow(sysWaterReducer.getCementPasteFlow());
                    vo.setReducerReducingRate(sysWaterReducer.getReducingRate());
                    vo.setReducerRegionNameStr(sysWaterReducer.getSourceName());

                }
            }


            //增效剂
            vo.setEfficiencyAgentAgent(smp.getEfficiencyAgent());
            Integer efficiencyAgentId = smp.getEfficiencyAgentId();
            if (efficiencyAgentId != null) {
                SysEfficiencyAgent efficiencyAgent = efficiencyAgentMap.get(efficiencyAgentId);
                if (efficiencyAgent != null) {
                    vo.setEfficiencyAgentModel(efficiencyAgent.getModel());
                    vo.setEfficiencyAgentSourceName(efficiencyAgent.getSourceName());
                }
            }


            //膨胀剂
            vo.setSwellingAgent(smp.getExpansionAgent());
            Integer swellingAgentId = smp.getExpansionAgentId();
            if (swellingAgentId != null) {
                SysSwellingagent sysSwellingagent = swellingagentMap.get(swellingAgentId);
                if (sysSwellingagent != null) {
                    vo.setSwellingagentModel(sysSwellingagent.getModel());
                    vo.setSwellingagentSourceName(sysSwellingagent.getSourceName());

                }
            }


            agentVOList.add(vo);
        }
        System.out.println("膨胀剂数据：" + agentList);

        // 导出 Excel
        ExcelUtil<SysMechanicalPerformanceFourthVO> util = new ExcelUtil<>(SysMechanicalPerformanceFourthVO.class);
        util.exportExcel(response, agentVOList, "坍落度数据导出");


    }





//    @PostMapping("/querSysSlumpy")
//    public AjaxResult querSysSlumpy(@RequestBody SysSlumpDTO sysSlumpDTO) {
//        // 调用服务层获取查询结果
//        List<SysSlumpVO> result = null;
//        result = sysSlumpService.querSysSlumpy(sysSlumpDTO);
//        try {
//            result = sysSlumpService.querSysSlumpy(sysSlumpDTO);
//        } catch (Exception e) {
//            return AjaxResult.error("请求异常");
//        }
//        // 返回结果
//        return AjaxResult.success(result);
//    }


    /**
     * 力学性能导出excel
     */
    @PostMapping("exportMechanicalPerformanceExcelText")
    public AjaxResult exportMechanicalPerformanceText(@RequestBody ExportMechanicalPerformanceExcelDTO exportMechanicalPerformanceExcelDTO) {
        List<Integer> mechanicalIds = exportMechanicalPerformanceExcelDTO.getMechanicalIds();
        List<SysMechanicalPerformance> sysMechanicalPerformanceList = mechanicalPerformanceService.exportMechanicalPerformance(mechanicalIds);

        return AjaxResult.success(sysMechanicalPerformanceList);
    }

    /**
     * 力学性能
     *
     * @param exportMechanicalPerformanceExcelDTO
     * @return
     * @throws IOException
     * @throws UnsupportedEncodingException
     */

    @PostMapping("exportAdditiveExcel")
    public ResponseEntity<byte[]> exportAdditiveExcel(@RequestBody ExportMechanicalPerformanceExcelDTO exportMechanicalPerformanceExcelDTO) throws IOException, UnsupportedEncodingException {
        // 获取各类原材料的 ID 列表

        List<Integer> mechanicalIds = exportMechanicalPerformanceExcelDTO.getMechanicalIds();
        List<SysMechanicalPerformance> sysMechanicalPerformanceList = mechanicalPerformanceService.exportMechanicalPerformance(mechanicalIds);


        // 创建一个 Excel 工作簿
        Workbook workbook = new XSSFWorkbook();
        createMechanicalPerformanceSheet(workbook, sysMechanicalPerformanceList);

        // 将 Excel 数据写入字节数组输出流
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        workbook.write(byteArrayOutputStream);
        byteArrayOutputStream.close();

        byte[] excelData = byteArrayOutputStream.toByteArray();
        String fileName = "力学性能数据.xlsx";

        // 对文件名进行 URL 编码
        String encodedFileName = URLEncoder.encode(fileName, "UTF-8").replaceAll("\\+", "%20");

        // 设置响应头，返回 Excel 文件
        HttpHeaders headers = new HttpHeaders();
        headers.add("Content-Disposition", "attachment; filename=" + encodedFileName);
        headers.add("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");

        return ResponseEntity.ok()
                .headers(headers)
                .body(excelData);
    }

    // 工具方法：创力学性能表 sheet

    private void createMechanicalPerformanceSheet(Workbook workbook, List<SysMechanicalPerformance> sysMechanicalPerformanceList) {
        // 创建一个名为 "力学性能" 的工作表
        Sheet sheet = workbook.createSheet("力学性能");

        // 创建表头
        Row headerRow = sheet.createRow(0);
        headerRow.createCell(0).setCellValue("力学性能ID");
        headerRow.createCell(1).setCellValue("7天抗压强度 (MPa)");
        headerRow.createCell(2).setCellValue("28天抗压强度 (MPa)");
        headerRow.createCell(3).setCellValue("地区名称");
        headerRow.createCell(4).setCellValue("水用量 (kg/m³)");
        headerRow.createCell(5).setCellValue("水泥ID");
        headerRow.createCell(6).setCellValue("水泥用量 (kg/m³)");
        headerRow.createCell(7).setCellValue("粉煤灰ID");
        headerRow.createCell(8).setCellValue("粉煤灰用量 (kg/m³)");
        headerRow.createCell(9).setCellValue("砂ID");
        headerRow.createCell(10).setCellValue("砂用量 (kg/m³)");
        headerRow.createCell(11).setCellValue("石ID");
        headerRow.createCell(12).setCellValue("石用量 (kg/m³)");

        headerRow.createCell(13).setCellValue("减水剂ID");
        headerRow.createCell(14).setCellValue("减水剂掺量 (%)");
        headerRow.createCell(15).setCellValue("增效剂ID");
        headerRow.createCell(16).setCellValue("增效剂掺量 (%)");

        // 填充数据
/*        int rowNum = 1;
        for (SysMechanicalPerformance performance : sysMechanicalPerformanceList) {
            Row row = sheet.createRow(rowNum++);
            row.createCell(0).setCellValue(safeToString(performance.getMechanicalId()));             // 力学性能ID
            row.createCell(1).setCellValue(safeToString(performance.getCompressiveStrength7d()));   // 7天抗压强度
            row.createCell(2).setCellValue(safeToString(performance.getCompressiveStrength28d()));  // 28天抗压强度
            row.createCell(3).setCellValue(safeToString(performance.getRegionNameStr()));           // 地区名称
            row.createCell(4).setCellValue(safeToString(performance.getWaterContent()));            // 水用量
            row.createCell(5).setCellValue(safeToString(performance.getCementId()));                // 水泥ID
            row.createCell(6).setCellValue(safeToString(performance.getCementContent()));           // 水泥用量
            row.createCell(7).setCellValue(safeToString(performance.getFlyashId()));                // 粉煤灰ID
            row.createCell(8).setCellValue(safeToString(performance.getFlyAshContent()));           // 粉煤灰用量
            row.createCell(9).setCellValue(safeToString(performance.getSandId()));                  // 砂ID
            row.createCell(10).setCellValue(safeToString(performance.getSandContent()));            // 砂用量
            row.createCell(11).setCellValue(safeToString(performance.getStoneId()));                // 石ID
            row.createCell(12).setCellValue(safeToString(performance.getStoneContent()));           // 石用量
            row.createCell(13).setCellValue(safeToString(performance.getReducerId()));                // 减水剂ID
            row.createCell(14).setCellValue(safeToString(performance.getWaterReducerDosage()));            // 减水剂掺量
            row.createCell(15).setCellValue(safeToString(performance.getAgentId()));              // 增效剂ID
            row.createCell(16).setCellValue(safeToString(performance.getEfficiencyAgentDosage()));          // 增效剂掺量
        }*/
    }

    // 辅助方法：安全地将值转换为字符串
    private String safeToString(Object value) {
        return value == null ? "" : value.toString();
    }


}
